<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>收营台</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="__PUBLIC__/weixin/css/mui.css" />
		<link rel="stylesheet" href="__PUBLIC__/weixin/css/public.css" />
		<link rel="stylesheet" href="__PUBLIC__/weixin/css/mui.picker.css" />
		<link rel="stylesheet" href="__PUBLIC__/weixin/css/mui.poppicker.css" />
		<style type="text/css">
			.mui-content {
				padding-bottom: 50px;
			}
			
			.cart-product-cell-2 {
				height: auto;
				min-height: 80px;
				padding-left: 10px;
				padding-right: 10px;
				box-sizing: border-box;
			}
			
			.cart-product-cell-3 {
				color: #e95d4e;
			}
			
			img.cart-product-cell-1 {
				width: 80px;
				height: 80px;
			}
			
			.cart-product-name {
				height: 25px;
				line-height: 25px;
				font-size: 16px;
			}
			/*地址*/
			
			.address-tit {
				padding-right: 8px;
			}
			
			.flex-item {
				color: #999;
			}
			
			.mui-table-view-cell:after {
				left: 0;
				background-color: #dadada;
			}
			
			.mui-table-view .mui-table-view-cell .mui-navigate-right:after {
				right: 10px;
				font-size: 20px;
				font-weight: bold;
			}
			
			.se-title {
				font-size: 16px;
				color: #2c3e50;
				font-weight: bold;
			}
			
			.mui-table-view:before,
			.mui-table-view:after {
				background-color: #dadada;
			}
			/*结算页面按钮颜色*/
			
			.btn-pay {
				color: #fff;
				background-color: #3ab7cb;
				border-color: #3ab7cb;
			}
                        

		</style>
	</head>

	<body>
		
		<div class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<div id="goodsList">
					<div class="p10 bg-white border_bottom layout-box flex-cell">
						<img class="cart-product-cell-1" src="__ROOT__{$data.goods_imgs}">
						<div class="flex-item cart-product-cell-2">
							<div class="cart-product-name mui-ellipsis">{$data.goods_name}</div>
                                                        <if condition="$data['spec_1']">
                                                            <div class="cart-product-cell-3">
                                                                {$data.spec_1} : {$data.goods_spec.spec_1}
                                                                <if condition="$data['spec_2']">
                                                                    ; {$data.spec_2} : {$data.goods_spec.spec_2}
                                                                </if>
                                                            </div>
                                                        </if>
                                                        
                                                        
							<div class="cart-product-cell-3">积分:{$data.integral}</div>
                                                        
							<p class="">数量：<span>1</span></p>
						</div>
					</div>
				</div>

				<ul class="mui-table-view mt10">
					<li class="mui-table-view-cell">
						<span class="se-title">收货地址</span>
					</li>
                                        
					<li id="address" class="mui-table-view-cell">
                                        <if condition="$addressInfo != ''">
                                            <a class="mui-navigate-right">
							<div class="layout-box pb5">
								<span class="address-tit">收<ins class="half_words"></ins>货<ins class="half_words"></ins>人:</span>
								<span class="flex-item">{$addressInfo.consignee}</span>
							</div>
							<div class="layout-box pb5">
								<span class="address-tit">邮<ins class="two_words"></ins>编:</span>
								<span class="flex-item">{$addressInfo.zip}</span>
							</div>
							<div class="layout-box pb5">
								<span class="address-tit">联系电话:</span>
								<span class="flex-item">{$addressInfo.tel}</span>
							</div>
							<div class="layout-box">
								<span class="address-tit">收货地址:</span>
								<span class="flex-item line-break">{$addressInfo.address}</span>
							</div>
						</a>
                                            <else />
											
                                            <a id="address" class="mui-navigate-right">
											<if condition="$noaddress eq -1"> 门店自提
											
											<else />
											请选择收货地址
											</if>
							
						</a>
                                        </if>
                                            
<!--						<a class="mui-navigate-right">
							<div class="layout-box pb5">
								<span class="address-tit">收<ins class="half_words"></ins>货<ins class="half_words"></ins>人:</span>
								<span class="flex-item">小明</span>
							</div>
							<div class="layout-box pb5">
								<span class="address-tit">邮<ins class="two_words"></ins>编:</span>
								<span class="flex-item">472300</span>
							</div>
							<div class="layout-box pb5">
								<span class="address-tit">联系电话:</span>
								<span class="flex-item">15000012236</span>
							</div>
							<div class="layout-box">
								<span class="address-tit">收货地址:</span>
								<span class="flex-item line-break">江苏省南京市雨花台区铁心桥街道 花神大道景明佳园拾景苑</span>
							</div>
						</a>-->
					</li>
				</ul>
				<ul class="mui-table-view mt10">
					<li class="mui-table-view-cell">
						<span class="se-title">支付方式</span>
					</li>
					<li class="mui-table-view-cell">
						<a id="payModePicker" class="mui-navigate-right">
							畅由积分
						</a>
					</li>
				</ul>

				<ul class="mui-table-view mt10">
					<li class="mui-table-view-cell">
						<span class="se-title">订单备注</span>
					</li>
					<li class="mui-table-view-cell">
						<input type="text" id="des" placeholder="请填写订单备注" />
					</li>
				</ul>
			</div>
		</div>
		<nav class="mui-bar mui-bar-tab">
			<div class="pt3 plr10">
				<button id="payFor" type="button" class="mui-btn mui-btn-block btn-pay">结算</button>
			</div>
		</nav>
	</body>
	<script src="__PUBLIC__/weixin/js/mui.js"></script>
	<script src="__PUBLIC__/weixin/js/mui.picker.min.js"></script>
	<script src="__PUBLIC__/weixin/js/mui.poppicker.js"></script>
        <script src="__PUBLIC__/js/jquery.min.js"></script>
	<script>
	var noaddress = "{$noaddress}";
		mui.init();
                var pay_type = 3;
                var address_id = "{$addressInfo.id}";
                var goods_id = "{$data.id}";
                var goods_spec_id = "{$data.goods_spec.id}";
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
		
		var modePicker = new mui.PopPicker();
		modePicker.setData([{
			value: '3',
			text: '畅由积分'
		}
		///,{
		//	value: '2',
		//	text: '微信支付'
		//},{
		//	value: '1',
		//	text: '线下支付'
		//}
		]);
		
		
		var payModePickerButton = document.getElementById('payModePicker');
		payModePickerButton.addEventListener('tap', function(event) {
			modePicker.show(function(items) {
				payModePickerButton.innerText = items[0].text;
                                pay_type = items[0].value;
			});
		}, false);
                
                document.getElementById("address").addEventListener('tap',function(){
					if(noaddress == -1){
						return false;
					}else{
						window.location.href = "{:U('Weixin/Index/address')}"+"?id="+goods_id+"&goods_spec_id="+goods_spec_id;
					}
                    
                });
                
                document.getElementById("payFor").addEventListener('tap',function(){
                    if(address_id == '' && noaddress != -1){
                        mui.alert("请填写购物地址!","提示","确定",function(){},'div');
                        return false;
                    }
                    $.ajax({
                        url:"{:U('Weixin/Index/buildOrder')}",
                        type:"post",
                        dataType:"json",
                        data:{
                            pay_type : pay_type,
                            goods_id : goods_id,
                            remark : $("#des").val(),
                            address_id : address_id ? address_id : noaddress,
                            spec_id : goods_spec_id
                        },
                        success:function(data){
                            if(pay_type == 1){
								if(data !== false){
									mui.alert("购买成功,请到门店自提!再看看其他商品吧!","提示","确定",function(){
										window.location.href = "{:U('Weixin/Index/index')}";
									},'div');
								}else{
									mui.alert("商品库存不足请联系卖家!","提示","确定",function(){},'div');
								}
                                
                            }else if(pay_type == 2){
                                jsApiCall(JSON.parse(data));
                            }else{
                                // 畅由积分购
                                console.log(data);
                                if(data !== false){
                                    //doSendCyForm(data);
                                    window.location.href = data.get_data;
                                }else{
									mui.alert("商品库存不足请联系卖家!","提示","确定",function(){},'div');
									return false;
								}
                            }
                        }
                    })
                })
                
        function doSendCyForm(formData){
            // 创建一个 form 
            console.log(formData);
            var form1 = document.createElement("form"); 
            form1.id = "form1"; 
            form1.name = "form1"; 
            // 添加到 body 中 
            document.body.appendChild(form1); 
            // 创建一个输入 
            for(var key in formData.data){
                
                var item = formData.data[key];
                
                var input = document.createElement("input"); 
                // 设置相应参数 
                input.type = "text"; 
                input.name = key; 
                input.value = item; 
                // 将该输入框插入到 form 中 
                form1.appendChild(input); 
            }
            
            // form 的提交方式 
            form1.method = "POST"; 
            // form 提交路径 
            form1.action = formData.action; 
            // 对该 form 执行提交 
            form1.submit(); 
            // 删除该 form 
            document.body.removeChild(form1); 
        }
        
        function onlinePay(){
            
        }
                
                //调用微信JS api 支付
	function jsApiCall(data)
	{
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			data,
			function(res){
//				WeixinJSBridge.log(res.err_msg);
//				alert(res.err_code+res.err_desc+res.err_msg);
                                //用户取消购买
                                if(res.err_msg == 'get_brand_wcpay_request:cancel'){
//                                    alert("用户自主取消");
                                }
                                if(res.err_msg == 'get_brand_wcpay_request:ok'){
                                    mui.alert("购买成功,请到门店自提!再看看其他商品吧!","提示","确定",function(){
                                        window.location.href = "{:U('Weixin/Index/index')}";
                                    },'div');
                                }
			}
		)
	}

	
	
        
        
	
	
        
	</script>

</html>